package org.chatboleh.bean;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.chatboleh.exception.EDMException;

public class PageTextElement extends DataObject {

	private int pageid;
	private int textelementid;

	public PageTextElement() {
	}

	public PageTextElement(long i) {
		super(i);
	}

	@Override
	protected String fieldnames() {
		return "pageid,textelementid";
	}

	@Override
	public List<PageTextElement> getList(String criteria) throws EDMException {
		List<PageTextElement> list = new ArrayList<PageTextElement>();

		try {
			openConnection();
			prepareStatement(selectlistquery(criteria));
			executeQuery();
			while (resultset.next()) {
				PageTextElement pagetextelement = new PageTextElement();
				pagetextelement.id = resultset.getLong("id");
				pagetextelement.loadResultSetIntoObject(resultset);
				list.add(pagetextelement);
			}
		} catch (SQLException e) {
			throw new EDMException(e);
		} finally {
			closeStatement();
		}
		return list;
	}

	@Override
	protected void loadResultSetIntoObject(ResultSet resultset) {
		try {
			this.pageid = resultset.getInt("pageid");
			this.textelementid = resultset.getInt("textelementid");
		} catch (SQLException e) {
			logger.error(e);
		}
	}

	@Override
	public void prepareUpdate() throws EDMException {
		try {
			ps.setInt(1, this.pageid);
			ps.setInt(2, this.textelementid);
		} catch (SQLException e) {
			throw new EDMException(e);
		}
	}

	@Override
	protected String tablename() {
		return "page_textelement";
	}

	public int getPageid() {
		return pageid;
	}

	public void setPageid(int pageid) {
		this.pageid = pageid;
	}

	public int getTextelementid() {
		return textelementid;
	}

	public void setTextelementid(int textelementid) {
		this.textelementid = textelementid;
	}


}
